import { createRouter, createWebHistory } from 'vue-router'
import { stopVideoTranscode } from '@/api/VideoPlayer'
import { ElMessage } from 'element-plus';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', name: 'login', meta: { title: '登录' }, component: () => import('@/views/Login.vue') },
    // 首页
    { path: '/home', name: 'home', meta: { title: '首页' }, component: () => import('../views/Home.vue') },
    // 后台模块
    {
      path: '/parentRouter', meta: { title: '后台管理' }, redirect: { name: 'liveStreaming' }, component: () => import('../views/ParentRouter.vue'),
      children: [
        // 视频模块
        { path: 'liveStreaming', name: 'liveStreaming', meta: { title: '直播观看' }, component: () => import('../views/video/LiveStreaming.vue') },
        { path: 'multiScreenPlayback', name: 'multiScreenPlayback', meta: { title: '多屏播放' }, component: () => import('../views/video/MultiScreenPlayback.vue') },
        { path: 'videoReview', name: 'videoReview', meta: { title: '录像回看' }, component: () => import('../views/video/VideoReview.vue') },
        { path: 'electronicMap', name: 'electronicMap', meta: { title: '电子地图' }, component: () => import('../views/video/ElectronicMap.vue') },
        { path: 'trackTrace', name: 'trackTrace', meta: { title: '轨迹追踪' }, component: () => import('../views/video/TrackTrace.vue') },
        // 设备模块
        { path: 'equipment', name: 'equipment', meta: { title: '设备管理' }, component: () => import('../views/management1/Equipment.vue') },
        { path: 'group', name: 'group', meta: { title: '分组管理' }, component: () => import('../views/management1/Group.vue') },
        // 用户模块
        { path: 'user', name: 'user', meta: { title: '用户管理' }, component: () => import('../views/management2/User.vue') },
        { path: 'role', name: 'role', meta: { title: '角色管理' }, component: () => import('../views/management2/Role.vue') },

        // 菜单权限
        { path: 'menu', name: 'menu', meta: { title: '菜单权限' }, component: () => import('../views/menu/Role.vue') },
        { path: 'roleMenu', name: 'roleMenu', meta: { title: '角色权限' }, component: () => import('../views/menu/UserRole.vue') },
        // 日志
        { path: 'log', name: 'log', meta: { title: '日志' }, component: () => import('../views/log/Logs.vue') },
      ]
    },

    { path: '/404', name: '404', meta: { title: '404找不到页面' }, component: () => import('../views/404.vue') },
    { path: '/:pathMatch(.*)', redirect: '/404' }
  ],
})

const aaa = ['/video'];

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()  
  if (to.meta.title == '直播观看') {
    return
  }
  stopVideoTranscode(1).then(res => {})
})

export default router
